﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class SaveMenu: MonoBehaviour 
{
	public string sSave;
	public Text tSave1, tSave2, tSave3;
	public InputField saveField;
	public Canvas saveMenu;
	public Texture2D save1, save2, save3;

	void Start()
	{
		GetSaveName();
	}

	IEnumerator savePNG(string saver)
	{
		yield return new WaitForEndOfFrame();
		renderer.material.mainTexture = RenderTextureFree.Capture(new Rect( 0f, 0f, Screen.width, Screen.height ), 0, 0, saver);
		//save1 = Resources.Load<Texture2D>("Textures/Save");
		AssetDatabase.Refresh();
	}

	public void SetSaveName(string saver)
	{
		sSave = saveField.value;
		PlayerPrefs.SetString("SAVENAME" + saver, sSave);
		PlayerPrefs.Save();
		saveMenu.enabled = false;
		Time.timeScale = Time.timeScale == 0 ? 1 : 0;
		StartCoroutine(savePNG(saver));
		saveMenu.enabled = true;
		Time.timeScale = Time.timeScale == 0 ? 1 : 0;
	}

	public void GetSaveName()
	{
		tSave1.text = PlayerPrefs.GetString("SAVENAME1");
		tSave2.text = PlayerPrefs.GetString("SAVENAME2");
		tSave3.text = PlayerPrefs.GetString("SAVENAME3");
	}
}